#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;
const int MOD = 1e8 - 3;

int n, m;
int a[N], b[N], d[N];
int pos[N];
ll ans;

void discrete(int a[N]) {
  rep(i, 1, n) d[i] = a[i];
  sort(d + 1, d + n + 1);
  rep(i, 1, n) a[i] = lower_bound(d + 1, d + n + 1, a[i]) - d;
}
void merge(int l, int mid, int r) {
  int i = l, j = mid + 1, k = l;
  while (i <= mid && j <= r) {
    if (a[i] <= a[j]) {
      ans += j - mid - 1;
      b[k++] = a[i++];
    } else {
      b[k++] = a[j++];
    }
  }
  while (i <= mid) {
    ans += j - mid - 1;
    b[k++] = a[i++];
  }
  while (j <= r) {
    b[k++] = a[j++];
  }
  rep(i, l, r) a[i] = b[i];
}
void mergesort(int l, int r) {
  if (l >= r) return;
  int mid = (l + r) >> 1;
  mergesort(l, mid);
  mergesort(mid + 1, r);
  merge(l, mid, r);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) cin >> b[i];
  discrete(a);
  discrete(b);
  rep(i, 1, n) pos[b[i]] = i;
  rep(i, 1, n) a[i] = pos[a[i]];
  mergesort(1, n);
  cout << ans % MOD;
  return 0;
}